export default (listeners = {}) => {
  return {
    rules: {
      username: [
        { required: true, message: '用户名不能为空', trigger: 'blur' },
        {
          min: 2,
          max: 20,
          message: '用户名长度必须介于 2 和 20 之间',
          trigger: 'blur',
        },
      ],
      password: [
        { required: function(form) { return !form.userId; }, message: '新增时密码不能为空', trigger: 'blur' },
        {
          min: 6,
          max: 100,
          message: '密码长度必须介于 6 和 100 之间',
          trigger: 'blur',
        },
      ],
      nickname: [
        { required: true, message: '用户昵称不能为空', trigger: 'blur' },
      ],
      tokens: [
        { required: true, message: '剩余调用次数不能为空', trigger: 'blur' },
      ],
      description: [
        { required: true, message: '用户描述不能为空', trigger: 'blur' },
      ],
      mobile: [
        {
          pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
          message: '请输入正确的手机号码',
          trigger: 'blur',
        },
      ],
      email: [
        {
          type: 'email',
          message: '请输入正确的邮箱地址',
          trigger: ['blur', 'change'],
        },
      ],
    },
    formItems: [
      {
        field: 'userId',
        type: 'input',
        label: '用户ID',
        config: {
          clearable: false,
          maxlength: 30,
          disabled: true,
        },
      },
      {
        field: 'username',
        type: 'input',
        label: '用户名',
        config: {
          clearable: false,
          maxlength: 30,
        },
      },
      {
        field: 'password',
        type: 'input',
        label: '密码',
        config: {
          clearable: false,
          showPassword: true,
          maxlength: 30,
          placeholder: '编辑时留空将保留原密码，填写则更新为新密码'
        },
      },
      {
        field: 'nickname',
        type: 'input',
        label: '用户昵称',
        config: {
          clearable: false,
        },
      },
      {
        field: 'mobile',
        type: 'input',
        label: '手机号',
        config: {
          clearable: false,
          maxlength: 11,
        },
      },
      {
        field: 'email',
        type: 'input',
        label: '邮箱',
        config: {
          clearable: false,
          maxlength: 50,
        },
      },
      {
        field: 'status',
        type: 'radio',
        options: [],
        label: '状态',
        isGroup: true,
        defaultValue: '0',
        config: {
          clearable: false,
        },
        optionConfig: {
          border: true,
        },
      },
      {
        field: 'tokens',
        type: 'input',
        label: '调用次数',
        config: {
          clearable: false,
        },
      },
      {
        field: 'description',
        type: 'textarea',
        label: '用户描述',
        config: {
          clearable: false,
          rows: 3,
        },
        layout: {
          xl: 24,
          lg: 24,
          md: 24,
          sm: 24,
          xs: 24,
        },
      },
      {
        field: 'openid',
        type: 'input',
        label: '微信openid',
        config: {
          clearable: false,
          maxlength: 50,
        },
      },
      {
        field: 'avatar',
        type: 'custom',
        label: '头像',
        renderComponent: 'AvatarUpload',
        config: {
          clearable: false,
        },
      },
    ],
    colLayout: {
      xl: 12,
      lg: 12,
      md: 12,
      sm: 12,
      xs: 24,
    },
    itemStyle: {
      padding: '0px 8px 0px 8px',
    },
    elFormConfig: {
      labelWidth: '80px',
    },
    hideItems: ref([]),
  }
}
